from abc import ABC, abstractmethod
from typing import Dict, Optional, List
from pathlib import Path

class TranslationEngine(ABC):
    """
    统一翻译引擎抽象接口
    支持文本翻译和音频翻译两种模式
    """
    
    @abstractmethod
    def translate_text(
        self, 
        text: str, 
        source_lang: str = "auto", 
        target_lang: str = "en"
    ) -> Dict:
        """
        文本翻译接口（保持向后兼容）
        
        Args:
            text: 源文本
            source_lang: 源语言代码 (如 'zh', 'en')
            target_lang: 目标语言代码 (如 'en', 'zh')
            
        Returns:
            Dict: 包含翻译结果的字典
            {
                "source_text": "源文本",
                "translated_text": "目标语言文本", 
                "source_lang": "zh",
                "target_lang": "en",
                "confidence": 0.95,
                "engine": "engine-name",
                "timestamp": "2025-08-15T10:00:00"
            }
        """
        pass
    
    @abstractmethod
    def translate_audio(
        self, 
        audio_path: str, 
        source_lang: str = "auto",
        target_lang: str = "en",
        enable_translation: bool = True,
        return_segments: bool = False
    ) -> Dict:
        """
        音频翻译接口（新增功能）
        
        Args:
            audio_path: 音频文件路径
            source_lang: 源语言代码 (如 'zh', 'en')
            target_lang: 目标语言代码 (如 'en', 'zh')
            enable_translation: 是否启用翻译
            return_segments: 是否返回分段信息
            
        Returns:
            Dict: 包含翻译结果的字典
            {
                "source_text": "源语言文本",
                "translated_text": "目标语言文本", 
                "source_lang": "zh",
                "target_lang": "en",
                "confidence": 0.95,
                "duration": 10.5,
                "engine": "engine-name",
                "timestamp": "2025-08-15T10:00:00",
                "segments": [...] # 如果return_segments=True
            }
        """
        pass
    
    @abstractmethod
    def batch_translate_text(self, texts: List[str], source_lang: str = "auto", target_lang: str = "en") -> List[Dict]:
        """批量文本翻译"""
        pass
    
    @abstractmethod
    def is_ready(self) -> bool:
        """检查引擎是否就绪"""
        pass
    
    @abstractmethod
    def get_supported_languages(self) -> Dict[str, list]:
        """获取支持的语言列表"""
        pass
    
    # 兼容性方法（向后兼容）
    def translate(self, text: str, source_lang: str = "auto", target_lang: str = "en") -> Dict:
        """兼容方法：调用 translate_text"""
        return self.translate_text(text, source_lang, target_lang)
